/**
 * 
 */
package cc.monggo.demo.io;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import javax.imageio.stream.FileImageOutputStream;
import javax.imageio.stream.ImageOutputStream;

/**
 * @author fangjinsong
 *
 */
public class FileInputStreamDemo {
	String root = "D:\\Documents and Settings\\fangjinsong\\桌面\\";

	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		FileInputStreamDemo demo = new FileInputStreamDemo();
		demo.getInputStream();
	}
	
	public void getInputStream() throws Exception{
		String path = root + "T2jtSKXlJXXXXXXXXX_!!187393481.jpg";
		InputStream fileInputStream = new FileInputStream(new File(path));
	
		byte[] buffer = new byte[fileInputStream.available()];
		int length = fileInputStream.available();
		System.out.println(length);
		fileInputStream.read(buffer, 0, length);
		
		ByteArrayOutputStream  output = new ByteArrayOutputStream();
		String outpath = root + "3.jpg";
		ImageOutputStream imagOutput = new FileImageOutputStream(new File(outpath));
		imagOutput.write(buffer,0,length-40000);
		//imagOutput.flush();
		imagOutput.close();
		
		//output.write(buffer);
		//System.out.println("a" + new String(output.toByteArray()));
	}

}
